package com.five.taotao.guide_classify;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.five.taotao.Adapter.SelectAdapter;
import com.five.taotao.R;
import com.five.taotao.entity.ProductList;
import com.five.taotao.guide.ClassifyFragment;
import com.five.taotao.util.DataManager;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class LeftFragment extends Fragment {

    @BindView(R.id.lv)
    ListView lv;

    private View v;
    List<ProductList> mData;
    SelectAdapter adapter;

    public LeftFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (v == null) {
            v = inflater.inflate(R.layout.fragment_left, container, false);
            ButterKnife.bind(this, v);
            mData = DataManager.getInstance().getProductList();
            adapter = new SelectAdapter(mData, getActivity());
            lv.setAdapter(adapter);
            adapter.changeSelect(0);//设置第1项被选中

            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    adapter.changeSelect(position);
                    ProductList data = mData.get(position);
                    ClassifyFragment classifyFragment = (ClassifyFragment) getParentFragment();
                    classifyFragment.right_frgment.refresh(data);
                }
            });
        }
        return v;
    }

}
